package com.steven.ourcontest.chat.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.steven.ourcontest.base.BaseViewModel
import com.steven.ourcontest.chat.api.ChatApi
import com.steven.ourcontest.chat.bean.ChatHistoryRes
import com.steven.ourcontest.utils.plusAssign

class FriendHistoryViewModel : BaseViewModel() {
    private val _queryFriendsResponse = MutableLiveData<ChatHistoryRes>()
    val queryFriendsResponse: LiveData<ChatHistoryRes>
        get() = _queryFriendsResponse

    private var isQueryingFriends = false
    fun queryFriends() {
        if (isQueryingFriends)
            return
        isQueryingFriends = true
        disposed += ChatApi.instance.queryChatFriends()
            .subscribe({
                isQueryingFriends = false
                _queryFriendsResponse.value = it
            }, {
                isQueryingFriends = false
                it.printStackTrace()
            })
    }
}